package Other.Version;

public class Version {
    public static void main(String[] args) {
        Solution.compareVersion("0.1", "0.2");
    }
}

// 165. 比较版本号
class Solution {
    public static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        for(int i=0;i<Math.min(v1.length,v2.length);i++){
            //1.001和1.01版本相同
            int n1 = Integer.parseInt(v1[i]);
            int n2 = Integer.parseInt(v2[i]);
            if(n1==n2)continue;
            return n1>n2?1:-1;
        }
        if(v1.length>v2.length){
            for(int i=v2.length;i<v1.length;i++){
                if(Integer.parseInt(v1[i])!=0) return 1;
            }
        }
        if(v2.length>v1.length){
            for(int i=v1.length;i<v2.length;i++){
                if(Integer.parseInt(v2[i])!=0) return -1;
            }
        }
        return 0;
    }
}
